package com.heo.coder;

import java.net.InetSocketAddress;

import org.apache.log4j.Logger;

import com.heo.coder.packet.base.BasePacket;
import io.netty.buffer.ByteBuf;
import io.netty.channel.ChannelHandlerContext;
import io.netty.handler.codec.MessageToByteEncoder;

public class HuaFuDeviceEncoder extends MessageToByteEncoder<BasePacket>{

	private static Logger log = Logger.getLogger(HuaFuDeviceEncoder.class);
	
	@Override
	protected void encode(ChannelHandlerContext ctx, BasePacket msg, ByteBuf out) throws Exception {
		String channelId = ctx.channel().id().asShortText();
	    String remoteIpAddress = ((InetSocketAddress) ctx.channel().remoteAddress()).getAddress().getHostAddress();
	    String logHeader = "[server][" + channelId + "][" + remoteIpAddress + "]";
//	    byte[] bytes = msg.getPacket();
//	    byte three = bytes[3];
//	    bytes[3] =  bytes[4];
//	    bytes[4] = three;
	    out.writeBytes(msg.getPacket());
//	    log.debug(logHeader + msg.getId() + "--->写入数据流，数据内容：" + msg.toString());
	}

}
